package com.sitc.administrator.application.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.View;


import com.sitc.administrator.application.R;
import com.sitc.administrator.application.activity.BaseCommonActivity;
import com.sitc.administrator.application.domain.StationInfos;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.sitc.administrator.application.activity.BaseWebViewActivity.start_WebView;
import static com.sitc.administrator.application.util.ToastUtil.showSortToast;


/**
 * 继承通用Adapter且使用通用Holder的适配器
 */
public class StationInfosAdapter extends CommonAdapter<StationInfos.RowsBean> {

    private Context mcontext;

    public StationInfosAdapter(Context context, List<StationInfos.RowsBean> list) {
        super(context, list, R.layout.item_station);
        mcontext = context;
    }

    /**
     * 复写抽象方法
     * @param viewHolder 一个ViewHolder
     * @param bean Bean对象
     */
    @Override
    public void setViewContent(CommonViewHolder viewHolder, final StationInfos.RowsBean bean) {

        //直接设置内容 链式调用
        final StationInfos.RowsBean item = bean;
        viewHolder.setText(R.id.station_name, item.getDcsName());
        viewHolder.setOnItemClick(R.id.list_item,new View.OnClickListener(){

            @Override
            public void onClick(View v) {

                //showSortToast(mcontext,"OK!!!!");

                BaseCommonActivity activity = (BaseCommonActivity) context;
                Map<String, String> map = new HashMap<String, String>();
                map.put("sysId","SITCAPP");
                map.put("stationId",String.valueOf(item.getDcsId()));
                map.put("token",activity.getSp().getToken());
                map.put("fileUrl",item.getFileUrl());


                String args = activity.getGs().toJson(map,Map.class);
                start_WebView(activity,item.getDcsName(),
                        "file:///android_asset/apps/webapp/web/siteDetails.html",args);

            }
        });
    }




}
